<?php

namespace app\api\controller\User;

use app\services\UserWorkService;
use app\services\WorkService;
use support\Request;

class WorkController
{
    public function getList(Request $request)
    {
        try {
            $page = $request->post('page', 1);
            $length = $request->post('length', 10);
            $isPay = $request->post('is_pay', null);

            $works = UserWorkService::getList($page, $length, $isPay);
            return ok_rsp('成功', $works);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function getChannelNames(Request $request)
    {
        try {
            $data = WorkService::getChannelNames();
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function getCountIncludeDel(Request $request)
    {
        try {
            $count = WorkService::getCountIncludeDeleted();
            return ok_rsp('成功', $count);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function getEditLink(Request $request)
    {
        try {
            $data = UserWorkService::getEditLink($request->post('order_no'));
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function getAddLink(Request $request)
    {
        try {
            $data = UserWorkService::getAddLink();
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function getPreviewLink(Request $request)
    {
        try {
            $data = UserWorkService::getPreviewLink($request->post('id'));
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function updateWorkInfo(Request $request)
    {
        try {
            $data = UserWorkService::updateWorkInfo($request->post('id'), $request->post('data'));
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }
}